/*! 
 * Header file for a structure that collect all relevant information
 * about collisions.
 *
 * \author Devis Rossini
 * \date 20 March 2012
 */
#ifndef PHXCOLLISIONDATA_H_INCLUDE_GUARD
#define PHXCOLLISIONDATA_H_INCLUDE_GUARD

#include "PhxContacts.h"

namespace phx
{
	/*!
     * A structure that contains information for the detector to use
     * in building its contact data.
     */
    struct CollisionData
    {
        /*!
         * Holds the base of the collision data: the first contact
         * in the array. This is used so that the contact pointer (below)
         * can be incremented each time a contact is detected, while
         * this pointer points to the first contact found.
         */
        Contact* mContactArray;

        /*! Holds the contact array to write into. */
        Contact* mContacts;

        /*! Holds the maximum number of contacts the array can take. */
        int mContactsLeft;

        /*! Holds the number of contacts found so far. */
        unsigned mContactCount;

        /*! Holds the friction value to write into any collisions. */
        real mFriction;

        /*! Holds the restitution value to write into any collisions. */
        real mRestitution;

        /*!
         * Holds the collision tolerance, even uncolliding objects this
         * close should have collisions generated.
         */
        real mTolerance;

        /*!
         * Checks if there are more contacts available in the contact
         * data.
         */
        bool HasMoreContacts()
        {
            return mContactsLeft > 0;
        }

        /*!
         * Resets the data so that it has no used contacts recorded.
         */
        void Reset(unsigned maxContacts)
        {
            mContactsLeft	= maxContacts;
            mContactCount	= 0;
            mContacts		= mContactArray;
        }

        /*!
         * Notifies the data that the given number of contacts have
         * been added.
         */
        void AddContacts(unsigned count)
        {
            // Reduce the number of contacts remaining, add number used
            mContactsLeft -= count;
			mContactCount += count;

            // Move the array forward
            mContacts += count;
        }
    };
}

#endif // PHXCOLLISIONDATA_H_INCLUDE_GUARD